﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Supermarket.Dal
{
    public static class CompanyDB
    {
        public static List<Company> GetAllCompanies()
        {
            DataClassesSupermarketDataContext db = new DataClassesSupermarketDataContext();
            var companies =
                from comp in db.Companies
                select comp;

            return companies.ToList<Company>();
        }

        public static void Update(int id, string name)
        {
            DataClassesSupermarketDataContext db = new DataClassesSupermarketDataContext();
            var company =
                from comp in db.Companies
                where comp.CompanyId == id
                select comp;

            company.First().CompanyName = name;
            db.SubmitChanges();
        }

        public static void CreateCompany(Company company)
        {
            DataClassesSupermarketDataContext db = new DataClassesSupermarketDataContext();
            db.Companies.InsertOnSubmit(company);
            db.SubmitChanges();
        }
    }
}
